<?php
/**
 * Config reader
 * @author Kirill Egorov 2010
 *
 */
/**
 * @todo Cleanup the code
 */

class Config {

    const File_Array = 0;
    const Inline = 1;
    /**
     * @var Store_Interface
     */
    static protected $_store = null;
	/**
      * @var Zend_Cache_Core
      */
     static protected $_cache = false;     
     /**
      * Set caching core
      * @param Zend_Cache_Core $core
      */
     public static function setCacheCore(Zend_Cache_Core $core){
         self::$_cache = $core;
     }
     /**
      * Get caching core
      * @return Zend_Cache_Core | null
      */
     public static function getCacheCore(){
         return self::$_cache;
     }
    
    static public function factory($type , $name){
        if(is_null(self::$_store))
            self::_connectStore();
            
        if(self::$_store->keyExists($name)){
            return self::$_store->get($name);
        }    
        
        $config = false;
        
        switch($type){
            case self::File_Array : $config = new Config_File_Array($name); 
                break;
            case self::Inline : $config = new Config_Inline($name); 
                break;
        }
        
        self::$_store->set($name , $config);
        return $config;
    }
    
    /**
     * Instantiate storage
     * @return void
     */
    static protected function _connectStore(){
        self::$_store = Store::factory(Store::Local , 'class_' . __CLASS__);
    } 
}